package com.ruoyi.production.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.ErpWorkOrder;
import com.ruoyi.production.service.IErpWorkOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@RestController
@RequestMapping("/production/production")
public class ErpWorkOrderController extends BaseController
{
    @Autowired
    private IErpWorkOrderService erpWorkOrderService;

    /**
     * 查询工单管理列表
     */
    @PreAuthorize("@ss.hasPermi('production:production:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpWorkOrder erpWorkOrder)
    {
        startPage();
        List<ErpWorkOrder> list = erpWorkOrderService.selectErpWorkOrderList(erpWorkOrder);
        return getDataTable(list);
    }

    /**
     * 导出工单管理列表
     */
    @PreAuthorize("@ss.hasPermi('production:production:export')")
    @Log(title = "工单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpWorkOrder erpWorkOrder)
    {
        List<ErpWorkOrder> list = erpWorkOrderService.selectErpWorkOrderList(erpWorkOrder);
        ExcelUtil<ErpWorkOrder> util = new ExcelUtil<ErpWorkOrder>(ErpWorkOrder.class);
        util.exportExcel(response, list, "工单管理数据");
    }

    /**
     * 获取工单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:production:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(erpWorkOrderService.selectErpWorkOrderByOrderId(orderId));
    }

    /**
     * 新增工单管理
     */
    @PreAuthorize("@ss.hasPermi('production:production:add')")
    @Log(title = "工单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpWorkOrder erpWorkOrder)
    {
        return toAjax(erpWorkOrderService.insertErpWorkOrder(erpWorkOrder));
    }

    /**
     * 修改工单管理
     */
    @PreAuthorize("@ss.hasPermi('production:production:edit')")
    @Log(title = "工单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpWorkOrder erpWorkOrder)
    {
        return toAjax(erpWorkOrderService.updateErpWorkOrder(erpWorkOrder));
    }

    /**
     * 删除工单管理
     */
    @PreAuthorize("@ss.hasPermi('production:production:remove')")
    @Log(title = "工单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(erpWorkOrderService.deleteErpWorkOrderByOrderIds(orderIds));
    }
}
